<?php
class ArrowFormAjax extends ArrowTagContainer{
	
	public function configure(){
		$this->addProperties(array(
			"target" => null,
			"targetText" => null,
			"beforeSubmit" => null,
			"success" => null,
			"debugTarget" => null,
			"error" => null,
			"beforeSerialize" => null
		));
	}
	
	public function init(){
		parent::init();
		$this->registerJsFile(  "./server/standardModels/org/arrowplatform/controls/forms/resources/jquery.form.js");

		$text = $this->getProperty("targetText");
		
		if(empty($text)){
			$template = $this->getFirstChild("ArrowCtrlTemplate");
			if($template)
				$text = $template->getSource();
		}
		
		$jsData = array(
			"target" => $this->getProperty("target"),
			"targetText" =>  $text,
			"beforeSubmit" =>  $this->getProperty("beforeSubmit"),
			"success" =>  $this->getProperty("success"),
			"error" =>  $this->getProperty("error"),
			"debugTarget" =>  $this->getProperty("debugTarget"),
			"beforeSerialize" =>  $this->getProperty("beforeSerialize")	
		
		
		);
		$this->registerJs( get_class($this), dirname(__FILE__)."/resources/ArrowFormAjax.js", "#".self::CTRL_NAMESPACE.'-ajax-form-location-'.$this->getGlobalId(), $jsData );
		
		$form = $this->getParent();
		
		$standardBean = $form->getProperty("actionBean");
		if($standardBean){
			$form->setProperty("actionBean", null);
			$form->setProperty("remoteBean", $standardBean);
		}
		
	}	
	
	public function generateBlockStart(){
		
		
		
		return '<div style="display:none;" id="ctrl-ajax-form-location-'.$this->getGlobalId().'"></div>';
	}
	public function generateBlockEnd(){}

}
?>